home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: Checking for Ilegal Input
- Date: 2 Mar 1996 09:05 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <2MAR199609054277@erich.triumf.ca>
- References: <313855C7.5E86@aol.com>
- NNTP-Posting-Host: erich.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <313855C7.5E86@aol.com>, gregace@aol.com writes...
- >I have a program where you must enter a number between 0 and 15 and check for
- >illegal input such as a number not between 0 and 15 or if a character is
- >entered.
- >
- >I used the scanf("%d",&number) to read the input.
-
- scanf() should be banned!
-
- It is very intolerant of unexpected input, as you have found. Instead of
- reading the user's input directly with scanf(), get the input with fgets(),
- then you can use sscanf(), and check it's return value to see if it got a
- number.
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
-
-
-
-
-
-